package com.itheima.test;

import com.itheima.dao.UserDao;
import com.itheima.pojo.User;
import com.itheima.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class MybatisTest1 {


    // 测试一下查询所有的功能
    @Test
    public void test01(){

        SqlSession sqlSession = MybatisUtils.openSession();

        UserDao userDao = sqlSession.getMapper(UserDao.class);

        List<User> users = userDao.queryAll();

        System.out.println(users);

        MybatisUtils.closeSession(sqlSession);

    }

    @Test
    public void test02(){
        //测试一下spring容器是否可以开启 并且可以使用 dao层调用功能完成 查询所有用户信息
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-dao.xml");

        UserDao userDao = context.getBean(UserDao.class);

        List<User> users = userDao.queryAll();

        System.out.println(users);

    }
}
